package com.tx.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.tx.entity.User;
import com.tx.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class MySecurityUserDetailServiceImpl implements UserDetailsService {

    @Autowired
    private IUserService userService;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        User user = userService.selectUserByUserName(username);

        if (ObjectUtil.isNull(user)){
            throw new UsernameNotFoundException("账号不存在");
        }

        return user;
    }
}


